import {
  Controller,
  Get,
  Request,
  Post,
  Body,
  Query,
  Delete,
  Param,
} from '@nestjs/common';
import { UserService } from '../service/user.service';
import { Public } from '../../core/decorators/publicGuards';
import { CreateUserDto } from '../dto/createUser.dto';
import { CommonPaginationServiceDto } from '@/modules/core/dto/pagination.dto';
import { UpdateUserDto } from '../dto/updateUser.dto';

@Controller('user')
export class UserController {
  constructor(private userService: UserService) {}
  @Get('profile')
  getProfile(@Request() req) {
    return req.user;
  }

  @Post('create')
  @Public()
  register(@Body() userInfo: CreateUserDto) {
    return this.userService.create(userInfo);
  }

  @Get('list')
  list(@Query() userInfo: CommonPaginationServiceDto) {
    return this.userService.list(userInfo);
  }

  @Delete('delete/:id')
  delete(@Param('id') id: string) {
    return this.userService.delete(id);
  }

  // 更新用户
  @Post('update/:id')
  update(@Param('id') id: string, @Body() body: UpdateUserDto) {
    return this.userService.update(id, body);
  }
}
